package org.joyflow.core.meta;

import lombok.Data;
import org.joyflow.core.instance.DbFactory;

import java.io.Serializable;

@Data
public class DbMeta {
    private Serializable id;
    private Serializable dbDirId;
    private Serializable dbTypeId;
    private Serializable dbConTypeId;
    private String name;
    private String hostname;
    private int port;
    private String dbName;
    private String username;
    private String password;
    private DatabaseInterface databaseInterface;

    public DbMeta() {
        setDefault();
    }

    public void setDefault() {

    }

    public String getDriverClass() {
        return databaseInterface.getDriverClass();
    }

    public String getURL() {
        return databaseInterface.getURL(hostname, port+"", dbName);
    }

    public Object testConnection() {
        return DbFactory.instance().test(this);
    }


    public String getFieldDefinition(FieldDefinition fieldDefinition) {
        return databaseInterface.getFieldDefinition(fieldDefinition);
    }

}
